﻿using HystereticBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HystereticRegularization
{
    /// <summary>
    /// 曲线正则化基方法
    /// </summary>
    public class CureveRegularizedSOE
    {
        /// <summary>
        /// 试验数据
        /// </summary>
        protected MontForceDispObj originalDataObj { set; get; }

        /// <summary>
        /// I点
        /// </summary>
        public ForceDispBasicPair PointI
        {
            get
            {
                return this.originalDataObj.First();
            }
        }

        /// <summary>
        /// J点
        /// </summary>
        public ForceDispBasicPair PointJ { set; get; }

        /// <summary>
        /// 是否正向加载
        /// </summary>
        public bool isPos
        {
            get
            {
                return this.PointEnd.Disp > this.PointI.Disp;
            }
        }

        /// <summary>
        /// 结束点 避免软化
        /// </summary>
        protected ForceDispBasicPair PointEnd
        {
            get
            {
                return originalDataObj.Last();
            }
        }

        /// <summary>
        /// 峰值力点
        /// </summary>
        protected ForceDispBasicPair PointForcePeak
        {
            get
            {
                return this.isPos ? this.originalDataObj.ForceMaxPoint : this.originalDataObj.ForceMinPoint;
            }
        }

        /// <summary>
        /// 是否求得最优值
        /// </summary>
        public bool isSuccess { set; get; }

        /// <summary>
        /// 等距离散后的力位移曲线
        /// </summary>
        protected MontForceDispObj SparaseObj { set; get; }

        /// <summary>
        /// 目标包围能量
        /// </summary>
        public double targetEnergy { set; get; }

        /// <summary>
        /// 数据点离散程度
        /// </summary>
        protected int regPtrNum { set; get; }

        /// <summary>
        /// 获得位移增量值
        /// </summary>
        protected float DeltaDisp
        {
            get
            {
                return (this.PointJ.Disp - this.PointI.Disp) / regPtrNum;
            }
        }

        /// <summary>
        /// 曲线正则化
        /// </summary>
        protected CurveRegularizedBasic paramObj { set; get; }

        /// <summary>
        /// 获得目标力位移曲线数据
        /// </summary>
        /// <returns></returns>
        protected MontForceDispObj GetSparaseTargetForceDispObj()
        {
            //获得正负号
            var deltaDisp = this.DeltaDisp;
            //增量是否为零
            if (this.DeltaDisp == 0) return new MontForceDispObj();
            //获得参数
            var obj = this.isSuccess ? this.paramObj.GetTargetForceDispObj(deltaDisp) :
                this.PointI.GetMontForceDispObj(this.PointJ, deltaDisp);
            //添加软化段参数
            if (Math.Abs(this.PointEnd.Disp - this.PointJ.Disp) > Math.Abs(deltaDisp))
                obj.AddRange(this.PointJ.GetMontForceDispObj(this.PointEnd, deltaDisp));
            return obj;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        protected CureveRegularizedSOE()
        {
            this.regPtrNum = HystereticRegParam.RegPrtNum;
        }
    }
}